//
//  GuideViewController.m
//  ShrimpCrowdordering
//
//  Created by 骆锴 on 2018/8/28.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "GuideViewController.h"
#import "GuideView.h"
#import "LoginViewController.h"
#import "BaseNavigationViewController.h"

@interface GuideViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIImageView  *background;
@property (nonatomic, strong) UIScrollView *baseView;

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setBaseView];
    [self setUI];
   _baseView.backgroundColor = REXADECIMALCOLOR(@"#ECEEF8");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setBaseView{
    _baseView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _baseView.backgroundColor = [UIColor whiteColor];
    _baseView.scrollEnabled = YES;
    _baseView.bounces = YES;
    _baseView.pagingEnabled = YES;
    _baseView.clipsToBounds = NO;
    _baseView.contentSize = CGSizeMake(SCREEN_WIDTH *3, SCREEN_HEIGHT);
    _baseView.showsHorizontalScrollIndicator = NO;
    _baseView.directionalLockEnabled = YES;
    _baseView.delegate = self;
    [self.view addSubview:_baseView];
}

-(void)setUI{
    for (int i = 0; i < 3; i++) {
        GuideView *view = [[GuideView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        if (i == 0) {
            [view setTitle:@"梦想"];
            [view setContent:@"梦想让设计更自由"];
            [view setImage:ImageWithName(@"组15")];
            [_baseView addSubview:view];
        }else if (i == 1){
            [view setTitle:@"价值"];
            [view setContent:@"价值让每个创意变现"];
            [view setImage:ImageWithName(@"组16")];
            [_baseView addSubview:view];
        }else{
            [view setTitle:@"定制"];
            [view setContent:@"定制让想法成现实"];
            [view setImage:ImageWithName(@"组17")];
            [view setBtn];
            view.sureClick = ^{
                kKeyWindow.rootViewController = [[BaseNavigationViewController alloc] initWithRootViewController:[[LoginViewController alloc] init]];
            };
            [_baseView addSubview:view];
        }
    }
    
    for (int i = 0; i < 3; i++) {
        UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(170) + ScreenX375(14) *i, ScreenX375(578), ScreenX375(8), ScreenX375(8))];
        if (i == 0) {
            [button setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
        }
        else{
            button.backgroundColor = REXADECIMALCOLOR(@"#d8d8d8");
        }
        button.clipsToBounds = YES;
        button.tag = 100 + i;
        button.layer.cornerRadius = 4.0;
        [self.view addSubview:button];
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x >= 0 && scrollView.contentOffset.x < SCREEN_WIDTH) {
        for (int i = 0 ; i < 3; i++) {
            UIButton *button = (UIButton *)[self.view viewWithTag:100 + i];
            button.backgroundColor = REXADECIMALCOLOR(@"#d8d8d8");
            [button setBackgroundImage:nil forState:UIControlStateNormal];
            button.hidden = NO;
            if (i == 0) {
                [button setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
            }
        }
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
        for (int i = 0 ; i < 3; i++) {
            UIButton *button = (UIButton *)[self.view viewWithTag:100 + i];
            button.backgroundColor = REXADECIMALCOLOR(@"#d8d8d8");
            button.hidden = NO;
            [button setBackgroundImage:nil forState:UIControlStateNormal];
            if (i == 1) {
                [button setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
            }
        }
    }else{
        for (int i = 0 ; i < 3; i++) {
            UIButton *button = (UIButton *)[self.view viewWithTag:100 +i];
            button.hidden = YES;
        }
    }
}

//- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//    if (scrollView.contentOffset.x == 0) {
//        for (int i = 0 ; i < 3; i++) {
//            UIButton *button = (UIButton *)[self.view viewWithTag:100 + i];
//            button.backgroundColor = REXADECIMALCOLOR(@"#d8d8d8");
//            [button setBackgroundImage:nil forState:UIControlStateNormal];
//            button.hidden = NO;
//            if (i == 0) {
//                [button setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
//            }
//        }
//    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
//        for (int i = 0 ; i < 3; i++) {
//            UIButton *button = (UIButton *)[self.view viewWithTag:100 + i];
//            button.backgroundColor = REXADECIMALCOLOR(@"#d8d8d8");
//            button.hidden = NO;
//            [button setBackgroundImage:nil forState:UIControlStateNormal];
//            if (i == 1) {
//                [button setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
//            }
//        }
//    }else{
//        for (int i = 0 ; i < 3; i++) {
//            UIButton *button = (UIButton *)[self.view viewWithTag:100 +i];
//            button.hidden = YES;
//        }
//    }
//}


@end
